<template>
	<view class="addressBook" :class='APPTheme'>
		<uni-nav-bar fixed status-bar title="通讯录" :color="APPTheme=='theme-light'?'#000000':'#ffffff'" :background-color="APPTheme=='theme-light'?'#ffffff':'#000000'"></uni-nav-bar>
		<u-cell-group class="theme-bg" :border="false">
			<u-cell-item title="组织通讯录" hover-class="theme-bg-active" title-width="600" @click="navigetTo('组织通讯录')"></u-cell-item>
			<u-cell-item title="角色通讯录" hover-class="theme-bg-active" title-width="600" @click="navigetTo('角色通讯录')"></u-cell-item>
		</u-cell-group>
		<u-cell-group title="常用联系人" class="theme-bg" :border="false">
			<u-cell-item v-for="(item,index) in topContacts" :key="index" :title="item.name" hover-class="theme-bg-active" title-width="600" @click="navigetToUesr(item)">
				<u-avatar slot="icon"  v-if="item.photo" :src="GLOBAL.image_svr+item.photo"  size="70" style="margin-right: 5px;"></u-avatar>
				<view slot="icon" class="text-warp" v-else style="margin-right: 5px;">{{computedUserInfo(item)}}</view>
			</u-cell-item>
		</u-cell-group>
		<!-- <u-empty mode="message"></u-empty> -->
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	let that
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapGetters(['APPTheme', 'userInfo', 'api']),
			computedUserInfo(){
				return (item)=>{
					let user=''
					if(item.name){
						user=item.name.slice(item.name.length-2,item.name.length);
					}
					return user
				}
			}
		},
		components: {},
		data() {
			return {
				topContacts:[],//常用联系人
			}
			
		},
		onLoad() {
			that = this
		},
		onShow() {
			//获取最近联系人
			that.getContacts()
		},
		methods: {
			//跳转
			navigetTo(name){
				if(name=='组织通讯录'){
					uni.navigateTo({url: '/pages/addressBook/OrgAddressBook/OrgAddressBook'});
				}else{
					uni.navigateTo({url: '/pages/addressBook/RoleAddressBook/RoleAddressBook'});
				}
			},
			navigetToUesr(item){
				uni.navigateTo({
					url: '/pages/addressBook/userInfo/userInfo?userId='+item.id,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//获取最近联系人
			getContacts(){
				that.GLOBAL.doGet(that.api.GLOBAL_rest_chat_message_getContacts,{}).then(res=>{
					console.log(res);
					if(res.code=='0'&&res.data){
						that.topContacts=res.data
					}
				})
			}
		}

	}
</script>

<style scoped lang="scss">
	.addressBook {
		height: 100%;
		.theme-bg{
			margin-bottom: 10px;
		}
		.text-warp{
			background: $bg-color;border-radius: 50%;width: 70rpx;height: 70rpx;font-size: 12px;display: flex;justify-content: center;align-items: center;color: #fff;
		}
	}
</style>
